package com.example.start.controller;

import com.example.start.common.CommonResp;
import com.example.start.common.MD5;
import com.example.start.entity.SysUser;
import com.example.start.req.SysUserLoginReq;
import com.example.start.req.SysUserReq;
import com.example.start.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys_user")
@CrossOrigin
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    //注册功能
    @PostMapping("/register")
    public CommonResp register(@RequestBody SysUserReq sysUserReq){
        CommonResp<SysUser> resp = new CommonResp<>();
        System.out.println(MD5.encrypt(sysUserReq.getPassword()));
        sysUserReq.setPassword(MD5.encrypt(sysUserReq.getPassword()));
        sysUserService.register(sysUserReq);
        return resp;
    }
    //登录功能
    @PostMapping("/login")
    public CommonResp login(@RequestBody SysUserLoginReq sysUserLoginReq){
        CommonResp resp = new CommonResp();
        sysUserLoginReq.setPassword(MD5.encrypt(sysUserLoginReq.getPassword()));
        SysUserLoginReq sysUserLoginReq1=sysUserService.login(sysUserLoginReq);
        resp.setContent(sysUserLoginReq1);
        return resp;
    }





}
